package cn.edu.hit.education.dialog;

import java.text.DecimalFormat;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import cn.edu.hit.education.pojo.College;
import cn.edu.hit.education.pojo.University;
import educationschedule.Activator;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.core.databinding.beans.PojoProperties;

public class CollegeDialog extends TitleAreaDialog {
	private DataBindingContext m_bindingContext;
	IPreferenceStore store = Activator.getDefault().getPreferenceStore();
	private Text textName;
	private Text textCode;
	private Text textNode;
	private College college;
	
	public CollegeDialog(Shell parentShell) {
		super(parentShell);
		// TODO Auto-generated constructor stub
	}
	
	protected Control createDialogArea(Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		composite.setLayout(new GridLayout(1, false));
		
		Composite composite_1 = new Composite(composite, SWT.NONE);
		composite_1.setLayout(new GridLayout(2, false));
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Label label = new Label(composite_1, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText("学院名称");
		
		textName = new Text(composite_1, SWT.BORDER);
		textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_1 = new Label(composite_1, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_1.setText("学院编码");
		
		textCode = new Text(composite_1, SWT.BORDER);
		textCode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_2 = new Label(composite_1, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_2.setText("备      注");
		
		textNode = new Text(composite_1, SWT.BORDER);
		textNode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		m_bindingContext = initDataBindings();
		
		return composite;
	}
	
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("添加新的学院");
	}

	public College getCollege() {
		return college;
	}

	public void setCollege(College college) {
		this.college = college;
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextTextNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(textName);
		IObservableValue nameCollegeObserveValue = PojoProperties.value("name").observe(college);
		bindingContext.bindValue(observeTextTextNameObserveWidget, nameCollegeObserveValue, null, null);
		//
		IObservableValue observeTextTextCodeObserveWidget = WidgetProperties.text(SWT.Modify).observe(textCode);
		IObservableValue codeCollegeObserveValue = PojoProperties.value("code").observe(college);
		bindingContext.bindValue(observeTextTextCodeObserveWidget, codeCollegeObserveValue, null, null);
		//
		IObservableValue observeTextTextNodeObserveWidget = WidgetProperties.text(SWT.Modify).observe(textNode);
		IObservableValue noteCollegeObserveValue = PojoProperties.value("note").observe(college);
		bindingContext.bindValue(observeTextTextNodeObserveWidget, noteCollegeObserveValue, null, null);
		//
		return bindingContext;
	}
}
